<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
	<% String path=request.getContextPath(); String basePath=request.getScheme() + "://" + request.getServerName() + ":"
		+ request.getServerPort() + path + "/" ; %>

		<!DOCTYPE html>
		<html>

		<head>
			<base href="<%=basePath%>">

			<title>外部用户表</title>

			<meta http-equiv="pragma" content="no-cache">
			<meta http-equiv="cache-control" content="no-cache">
			<meta http-equiv="expires" content="0">
			<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
			<meta http-equiv="description" content="This is my page">
			<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

		</head>

		<body>
			<%@ include file="/WEB-INF/jsp/common/headerSupply.jsp" %>
				<%@ include file="/WEB-INF/jsp/common/loadDiv.jsp" %>

					<script type="text/javascript">
						$(function () {
							bindgrid();
						});
					</script>
					<script>
						function del(node) {
							$.ajax({
								type: "delete",
								url: 'supply/user/delete?id=' + node.userId,
								//                dataType: "xml",				
								success: function (data) {
									$.messager.alert('消息', data.msg);
									$('#add').window('close');
									bindgrid();
								},
								error: function (XMLHttpRequest, textStatus, errorThrown) {
									$.messager.alert('消息', errorThrown);
								}
							});
						}

						function save() {
							if (!$('#fm').form('validate')) {
								return;
							}
							var user = $('#dg').datagrid('getSelected');
							console.log('user:', user);
							var model = {
								userId: $('#userId').val(),
								infId: PUser.infId,
								inforName: PUser.inforName,
								userAccout: $('#userAccout').textbox('getValue'),
								userName: $('#userName').textbox('getValue'),
								userPwd: $('#userPwd').textbox('getValue'),
								// 				userIsAdmin : $('#userIsAdmin').textbox('getValue')
							};
							console.log('JSON.stringify(model):', JSON.stringify(model));
							$.ajax({
								type: "post",
								dataType: "json",
								url: 'supply/user/save',
								data: JSON.stringify(model),
								contentType: "application/json",
								success: function (data) {
									if (data.code != 60200) {
										$.messager.alert('消息', data.msg);
									} else {
										$.messager.alert('消息', data.msg);
										let dg = $('#dg');
										dg.datagrid('enableFilter');
										dg.datagrid('load');
										$('#add').window('close');
									}
								},
								error: function (XMLHttpRequest, textStatus, errorThrown) {
									$.messager.alert('消息', errorThrown);
								}
							})
						}

						function editrow() {
							//编辑用户
							var user = $('#dg').datagrid('getSelected');
							if (user) {
								$('#add').window('open');
								// 				$('#t1').val(user.userid);

							} else {
								$.messager.alert('消息', '请选中一个用户');
							}
						}
					</script>
					<script>
						function bindgrid() {
							$('#dg').datagrid(
								{
									title: '用户列表',
									url: "supply/user/selectList",
									iconCls: 'icon-application',
									width: getWidth(0.98),
									height: 415,
									nowrap: true,
									rownumbers: true,
									animate: false,
									collapsible: false,
									clientPaging: false,
									remoteFilter: true,
									singleSelect: true,
									pagination: true,
									remoteSort: true,
									columns: [[{
										field: 'inforId',
										title: '供应商姓名',
										sortable: true,
										hidden: true,
										formatter: function (val, rec) {
											return unescape(val)
										}
									}, {
										field: 'userId',
										title: 'userId',
										sortable: true,
										hidden: true,
										formatter: function (val, rec) {
											return unescape(val)
										}
									}, {
										field: 'inforName',
										title: '供应商姓名',
										sortable: true,
										formatter: function (val, rec) {
											return unescape(val)
										}
									}, {
										field: 'userAccout',
										title: '用户账号',
										sortable: true,
										formatter: function (val, rec) {
											return unescape(val)
										}
									}, {
										field: 'userName',
										title: '用户姓名',
										sortable: true,
										formatter: function (val, rec) {
											return unescape(val)
										}
										// 						}, {
										// 							field : 'userPwd',
										// 							title : '用户密码',
										// 							sortable : true,
										// 							formatter : function(val, rec) {
										// 								return unescape(val)
										// 							}
										// 						}, {
										// 							field : 'userIsAdmin',
										// 							title : '是否企业管理员',
										// 							sortable : true,
										// 							formatter : function(val, rec) {
										// 								return unescape(val)
										// 							}
									}, {
										field: 'createTime',
										title: '创建时间',
										sortable: true,
										formatter: function (val, rec) {
											return val ? val : '';
										}
									}, {
										field: 'createName',
										title: '创建人',
										sortable: true,
										formatter: function (val, rec) {
											return val ? val : '';
										}
										// 						}, {
										// 							field : 'createId',
										// 							title : 'create_id',
										// 							sortable : true,
										// 							hidden : true,
										// 							formatter : function(val, rec) {
										// 								return unescape(val)
										// 							}
										// 						}, {
										// 							field : 'updateId',
										// 							title : '修改人id',
										// 							sortable : true,
										// 							hidden : true,
										// 							formatter : function(val, rec) {
										// 								return unescape(val)
										// 							}
										// }, {
										// 	field: 'updateName',
										// 	title: '修改人',
										// 	sortable: true,
										// 	formatter: function (val, rec) {
										//         return val ? val : '';
										// 	}
										// }, {
										// 	field: 'updateTime',
										// 	title: '修改时间',
										// 	sortable: true,
										// 	formatter: function (val, rec) {
										//         return val ? val : '';
										// 	}
										// }, {
										// 	field: 'delFlag',
										// 	title: '是否删除',
										// 	sortable: true,
										// 	formatter: function (val, rec) {
										// 		return unescape(val)
										// 	}
										// }, {
										// 	field: 'status',
										// 	title: '状态',
										// 	sortable: true,
										// 	formatter: function (val, rec) {
										// 		return unescape(val)
										// 	}
										// }, {
										// 	field: 'remark',
										// 	title: '备注',
										// 	sortable: true,
										// 	formatter: function (val, rec) {
										// 		return unescape(val)
										// 	}
									}]],
									toolbar: [
										{
											text: '增加',
											iconCls: 'icon-add',
											handler: function () {
												$('#fm').form('clear');
												$('#userId').val('');
												$('#userAccout').textbox('enable');
												$('#add').window('open');
											}
										},
										'-',
										{
											text: '编辑',
											iconCls: 'icon-edit',
											handler: function () {
												var row = $('#dg').datagrid(
													'getSelected');
												if (row) {
													$('#add').dialog('open').dialog(
														'center').dialog(
															'setTitle', '');
													$('#fm').form('load', row);
													$('#userAccout').textbox('disable');
													$('#userPwd').textbox('setText', '');
													$('#userId').val(row.userId);
												}
											}
										},
										'-',
										{
											text: '删除',
											iconCls: 'icon-cancel',
											handler: function () {
												var row = $('#dg').datagrid(
													'getSelected');
												if (row) {
													if (row.userAccout == PUser.userAccout) {
														$.messager.alert('提示', '不能删除本人');
														return;
													}
													$.messager.confirm('提示',
														'确定要删除吗?', function (r) {
															if (r) {
																del(row);
															}
														});
												}
											}
										}],
									onLoadSuccess: function () {
									},
									onDblClickRow: function () {
										// 							editrow();
									}
								});
							$('#dg').datagrid('enableFilter');
						}
					</script>
					<style scoped="scoped">
						.textbox {
							height: 20px;
							margin: 0;
							padding: 0 2px;
							box-sizing: content-box;
						}

						/*.table tr {
        height: 15px;
    }*/
					</style>

					<div class="query_criteria" id="query_criteria">
						<table id="dg"></table>


						<div id="add" class="easyui-window" closed="true" modal="true" title="用户信息"
							style="width: 500px; height: 450px; padding: 10px 20px">
							<form id="fm" class="ssec-form">
								<table class="table">
									<!-- 					<tr> -->
									<!-- 						<td> -->
									<!-- 							<div class="ssec-label">用户id：</div> -->
									<!-- 						</td> -->
									<!-- 						<td> -->
									<!-- 							<div class="ssec-text normal"> -->
									<!-- 								<input id="userId" name="userId" class="easyui-textbox" -->
									<!-- 									data-options="required:true" /> -->
									<!-- 							</div> -->
									<!-- 						</td> -->
									<!-- 					</tr> -->
									<!-- 					<tr> -->
									<!-- 						<td> -->
									<!-- 							<div class="ssec-label">供应商id：</div> -->
									<!-- 						</td> -->
									<!-- 						<td> -->
									<!-- 							<div class="ssec-text normal"> -->
									<!-- 								<input id="infId" name="infId" class="easyui-textbox" -->
									<!-- 									data-options="required:true" /> -->
									<!-- 							</div> -->
									<!-- 						</td> -->
									<!-- 					</tr> -->
									<!-- 					<tr> -->
									<!-- 						<td> -->
									<!-- 							<div class="ssec-label">供应商姓名：</div> -->
									<!-- 						</td> -->
									<!-- 						<td> -->
									<!-- 							<div class="ssec-text normal"> -->
									<!-- 								<input id="inforName" name="inforName" class="easyui-textbox" -->
									<!-- 									style="width: 100px;" data-options="required:true" /> -->
									<!-- 							</div> -->
									<!-- 						</td> -->
									<!-- 					</tr> -->
									<tr>
										<td>
											<div class="ssec-label">用户账号：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input type="hidden" id="userId" />
												<input id="userAccout" name="userAccout" class="easyui-textbox"
													data-options="required:true,disabled:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">用户姓名：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="userName" name="userName" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">用户密码：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="userPwd" name="userPwd" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<!-- 					<tr> -->
									<!-- 						<td> -->
									<!-- 							<div class="ssec-label">是否企业管理员：</div> -->
									<!-- 						</td> -->
									<!-- 						<td> -->
									<!-- 							<div class="ssec-text normal"> -->
									<!-- 								<input id="userIsAdmin" name="userIsAdmin" -->
									<!-- 									class="easyui-textbox" data-options="required:true" /> -->
									<!-- 							</div> -->
									<!-- 						</td> -->
									<!-- 					</tr> -->
								</table>
								<div style="padding: 5px; text-align: right;">
									<a class="easyui-linkbutton" onclick="save();" iconcls="icon-save">保存</a>
								</div>
							</form>
						</div>
					</div>
		</body>

		</html>